﻿using EBFHelper.EBFHelperUtil;
using EBFHelper.Nodes;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace EBFHelper.forms
{
    public partial class CommConfigInfoForm : Form
    {

        private List<iNode> m_commConfigXmlList;

        public CommConfigInfoForm(List<iNode> commConfigXmlList)
        {
            m_commConfigXmlList = commConfigXmlList;
            InitializeComponent();
            foreach (iNode inode in m_commConfigXmlList)
            {
                CommConfigXmlNode commConfigXmlNode = null;

                if (null == (commConfigXmlNode = inode as CommConfigXmlNode))
                {
                    continue;
                }
                
                switch (commConfigXmlNode.name)
                {
                    case "EBData.xml":
                        HelperDisplayUtil.buildDiffrentTreesAccordingToDiffrentCommConfigs(commConfigXmlNode, EBDataTreeView);
                        break;
                    case "EBDatabaseConfig.xml":
                        HelperDisplayUtil.buildDiffrentTreesAccordingToDiffrentCommConfigs(commConfigXmlNode, EBDataBaseConfigTreeView);
                        break;
                    case "EBService.xml":
                        HelperDisplayUtil.buildDiffrentTreesAccordingToDiffrentCommConfigs(commConfigXmlNode, EBServiceTreeView);
                        break;
                    case "EBOperation.xml":
                        HelperDisplayUtil.buildDiffrentTreesAccordingToDiffrentCommConfigs(commConfigXmlNode, EBOperationTreeView);
                        break;
                    case "EBFormat.xml":
                        HelperDisplayUtil.commAvailableFmt.Clear();
                        HelperDisplayUtil.buildDiffrentTreesAccordingToDiffrentCommConfigs(commConfigXmlNode, EBFormatTreeView);
                        break;
                    case "EBContext.xml":
                        HelperDisplayUtil.buildDiffrentTreesAccordingToDiffrentCommConfigs(commConfigXmlNode, EBContextTreeView);
                        HelperDisplayUtil.commDataNodes.Clear();
                        HelperDisplayUtil.addCommDataNodes();
                        break;
                    default:
                        break;
                }
            }
            
            
        }

        private void EBDataTreeView_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            MyTreeNode tNode;
            if (null == (tNode = EBDataTreeView.SelectedNode as MyTreeNode))
            {
                return;
            }

            XmlNodeAtrributeInfo xNAI = new XmlNodeAtrributeInfo(tNode);
            xNAI.Show();
        }

        private void EBDataBaseConfigTreeView_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            MyTreeNode tNode;
            if (null == (tNode = EBDataBaseConfigTreeView.SelectedNode as MyTreeNode))
            {
                return;
            }

            XmlNodeAtrributeInfo xNAI = new XmlNodeAtrributeInfo(tNode);
            xNAI.Show();
        }

        private void EBServiceTreeView_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            MyTreeNode tNode;
            if (null == (tNode = EBServiceTreeView.SelectedNode as MyTreeNode))
            {
                return;
            }

            XmlNodeAtrributeInfo xNAI = new XmlNodeAtrributeInfo(tNode);
            xNAI.Show();
        }

        private void EBFormatTreeView_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            MyTreeNode tNode;
            if (null == (tNode = EBFormatTreeView.SelectedNode as MyTreeNode))
            {
                return;
            }

            XmlNodeAtrributeInfo xNAI = new XmlNodeAtrributeInfo(tNode);
            xNAI.Show();
        }

        private void EBContextTreeView_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            MyTreeNode tNode;
            if (null == (tNode = EBContextTreeView.SelectedNode as MyTreeNode))
            {
                return;
            }

            XmlNodeAtrributeInfo xNAI = new XmlNodeAtrributeInfo(tNode);
            xNAI.Show();
        }

        private void EBOperationTreeView_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            MyTreeNode tNode;
            if (null == (tNode = EBOperationTreeView.SelectedNode as MyTreeNode))
            {
                return;
            }

            XmlNodeAtrributeInfo xNAI = new XmlNodeAtrributeInfo(tNode);
            xNAI.Show();
        }

        private void EBDataTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (MouseButtons.Right != e.Button) return;
            if (null == e.Button) return;
            EBDataTreeView.SelectedNode = e.Node;
            HelperModifyUtil.initContextMenuStrip();
            HelperModifyUtil.showContextMenuStrip(EBDataTreeView, e.X, e.Y, (MyTreeNode)e.Node);
        }

        private void EBDataBaseConfigTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (MouseButtons.Right != e.Button) return;
            if (null == e.Button) return;
            EBDataBaseConfigTreeView.SelectedNode = e.Node;
            HelperModifyUtil.initContextMenuStrip();
            HelperModifyUtil.showContextMenuStrip(EBDataBaseConfigTreeView, e.X, e.Y, (MyTreeNode)e.Node);
        }

        private void EBServiceTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (MouseButtons.Right != e.Button) return;
            if (null == e.Button) return;
            EBServiceTreeView.SelectedNode = e.Node;
            HelperModifyUtil.initContextMenuStrip();
            HelperModifyUtil.showContextMenuStrip(EBServiceTreeView, e.X, e.Y, (MyTreeNode)e.Node);
        }

        private void EBOperationTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (MouseButtons.Right != e.Button) return;
            if (null == e.Button) return;
            EBOperationTreeView.SelectedNode = e.Node;
            HelperModifyUtil.initContextMenuStrip();
            HelperModifyUtil.showContextMenuStrip(EBOperationTreeView, e.X, e.Y, (MyTreeNode)e.Node);
        }

        private void EBFormatTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (MouseButtons.Right != e.Button) return;
            if (null == e.Button) return;
            EBFormatTreeView.SelectedNode = e.Node;
            HelperModifyUtil.initContextMenuStrip();
            HelperModifyUtil.showContextMenuStrip(EBFormatTreeView, e.X, e.Y, (MyTreeNode)e.Node);
        }

        private void EBContextTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (MouseButtons.Right != e.Button) return;
            if (null == e.Button) return;
            EBContextTreeView.SelectedNode = e.Node;
            HelperModifyUtil.initContextMenuStrip();
            HelperModifyUtil.showContextMenuStrip(EBContextTreeView, e.X, e.Y, (MyTreeNode)e.Node);
        }


    }
}
